#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5,M=1e5+5,Q=2e2+5;
long long n,c,dp[N][N],dp1[M][Q],top,qwq[M*10];
struct node{
	long long id,z,now;
}a[M*10],b[M*10];
bool cmp(node i,node j)
{
	return i.z<j.z;
}
bool cmp1(node i,node j)
{
	return i.id<j.id;
}
int main()
{
	freopen("minimize.in","r",stdin);
	freopen("minimize.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>c;
	for(int i=1;i<=n;++i)
		cin>>a[i].z,a[i].id=i;
	sort(a+1,a+n+1,cmp);
	a[0].z=-1;
	for(int i=1;i<=n;++i)
	{
		if(a[i].z!=a[i-1].z) ++top,qwq[top]=a[i].z;
		a[i].now=top;
	}
	sort(a+1,a+n+1,cmp1);
	if(c==0)
		cout<<0;
	else if(top<=200)
	{
		for(int i=0;i<=n;++i)
			for(int j=1;j<=top+1;++j)
				dp1[i][j]=1e18;
		dp1[0][top]=0;
		for(int i=1;i<=n;++i)
		{
			for(int j=top;j>=1;--j)
				dp1[i][j]=min(dp1[i][j+1],dp1[i-1][j]);
			for(int j=top;j>=1;--j)
			{
				if(qwq[j]>=a[i].z)
					dp1[i][j]+=qwq[j]-a[i].z;
				else
					dp1[i][j]+=c;
			}
		}
		long long ans=1e18;
		for(int i=1;i<=top;++i)
			ans=min(dp1[n][i],ans);
		cout<<ans;
	}
	else{
		for(int i=0;i<=n;++i)
			for(int j=1;j<=top+1;++j)
				dp[i][j]=1e18;
		dp[0][top]=0;
		for(int i=1;i<=n;++i)
		{
			for(int j=top;j>=1;--j)
				dp[i][j]=min(dp[i][j+1],dp[i-1][j]);
			for(int j=top;j>=1;--j)
			{
				if(qwq[j]>=a[i].z)
					dp[i][j]+=qwq[j]-a[i].z;
				else
					dp[i][j]+=c;
			}
		}
		long long ans=1e18;
		for(int i=1;i<=top;++i)
			ans=min(dp[n][i],ans);
		cout<<ans;
	}
	return 0;
}
